﻿/*
 * BFind - A tool for finding football matches for trading on Betfair
 * Copyright 2009, 2010 Magnus Olsson <magnus72(at)gmail.com>
 * 
 * This file is part of BFind.
 * 
 * BFind is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 * 
 * BFind is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with BFind.  If not, see <http://www.gnu.org/licenses/>
*/


using System;
using System.Collections.Generic;
using System.IO;

namespace betfairfind
{
    static class Util
    {
        static public string[] readTextFile(string path)
        {
            List<string> l = new List<string>();
            try
            {
                FileStream file = new FileStream(path, FileMode.Open, FileAccess.Read);
                StreamReader reader = new StreamReader(file);
                string line = "";
                while (line != null)
                {
                    line = reader.ReadLine();
                    if (line != null)
                    {
                        l.Add(line);
                    }
                }
                
            }
            catch (Exception)
            {
                
            }
            return l.ToArray();
        }
         
        static public void appendTextFile(string path, string data)
        {
            try
            {
                FileStream file = new FileStream(path, FileMode.Append, FileAccess.Write);
                StreamWriter obj = new StreamWriter(file);
                obj.Write(data);
             //   obj.Flush();
                obj.Close();

            }
            catch (Exception ex)
            {
                Logger.Log(ex.ToString(), true, true);
            }
        } //returns StreamWriter to a file

        static public void writeTextFile(string path, string data)
        {
            try
            {
                FileStream file = new FileStream(path, FileMode.OpenOrCreate, FileAccess.Write);
                StreamWriter obj = new StreamWriter(file);
                obj.Write(data);
              //  obj.Flush();
                obj.Close();

            }
            catch (Exception ex)
            {
                Logger.Log(ex.ToString(), true, true);
            }
        } //returns StreamWriter to a file
    }
}
